<?php

class contIndex extends commController
{
    public $action = 'index';
    
    private $aCss = array(
                'name' => 'cont.login',
                'file_list' => array()
            );
    
    private $aJs = array(
                'name' => 'cont.login',
                'file_list' => array()
            );

    public function __construct($params = array())
    {
        parent::__construct($params);
    }

    public function index()
    {
        utilMust::locationReplace('/cont/?c=main');
    }
    
    public function login()
    {
        commViewer::_css($this->aCss);
        $aJs = array(
            'name' => 'cont.login2',
            'file_list' => array('util/util.form.validator')
        );
        commViewer::_js($aJs);

        // layout 비활성
        //$this->sTopLayoutView = false;
        //$this->sFooterLayoutView = false;
        
        $sReturnUrl = '/';
        if (empty($this->params['return_url']) === false) $sReturnUrl = $this->params['return_url'];

        $aAssignData = array(
            'return_url' => $sReturnUrl
        );

        // display view
        $this->view('/cont/login.html', $aAssignData);
    }

    /**
     *
     * 로그인 처리
     */
    public function setLogin()
    {
        /*
        // 임시 로그인
        $returnUrl = '/';
        if ($this->params['user_id'] == 'gudals') {
            $aLoginInfo = array(
                'sId' => 'gudals',
                'sType' => 'admin',
                'sLevel' => 1,
                'sName' => '구달스'
            );

            $returnUrl = '/cont/';
        }
        */
        
        $aParam = $this->params;
        
        $aUserInfo = m('user_info')->geLoginInfo($aParam);
        //print_r($aUserInfo);
        if (empty($aUserInfo['user_no'])) {
            utilData::jsonSingle(201);
            exit;
        }
        
        $aLoginInfo['sNo'] = $aUserInfo['user_no'];
        $aLoginInfo['sId'] = $aUserInfo['user_email'];
        $aLoginInfo['sNick'] = $aUserInfo['user_nick'];
        $aLoginInfo['sGender'] = $aUserInfo['user_gender'];
        $aLoginInfo['sBirth'] = $aUserInfo['user_birth'];
        $aLoginInfo['sPhoto'] = $aUserInfo['user_photo'];
        $aLoginInfo['sLevel'] = $aUserInfo['user_level'];

        foreach ($aLoginInfo as $key => $val) {
            commSession::session_register($key, $val);
        }
        
        commSession::register();

        $sReturnUrl = '/';
        if (empty($aParam['return_url']) === false) $sReturnUrl = $aParam['return_url'];
        
        utilData::jsonSingle(200);
        exit;
        
        //utilMust::alert('정상', $sReturnUrl,'top');
        //exit;
        
        //utilMust::locationReplace($sReturnUrl);

        header("location: ".$sReturnUrl);

        // 아이디 비번을 체크
    }
    
    /**
    *
    * 로그아웃
    */
    public function logout()
    {
        commSession::session_destroy();
        utilMust::locationReplace('/');
    }
}